package cn.wu.jishupeizhi.redisTest;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.test.context.junit4.SpringRunner;

@SpringBootTest
@RunWith(SpringRunner.class) // 确保测试类在 Spring 上下文中运行
public class RedisHash {

    @Autowired
    private RedisTemplate<String, Object> redisTemplate;

    @Test
    public void redisHashAdd() {
        redisTemplate.opsForHash().put("hash", "key1", "value1");
        redisTemplate.opsForHash().put("hash", "key2", "value2");
        redisTemplate.opsForHash().put("hash", "key3", "value3");
    }

    @Test
    public void redisHashGet() {
        Object value = redisTemplate.opsForHash().get("hash", "key2");
        System.out.println("Value for key1: " + value);
    }

    @Test
    public void redisHashDel() {
        redisTemplate.opsForHash().delete("hash", "key2");
    }

}
